package _zuoye._04;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.ArrayList;
import java.util.List;

public class Demo04_副本 {
    public static void main(String[] args) throws DocumentException {
        SAXReader reader = new SAXReader();
        Document document = reader.read("Day_14\\src\\_zuoye\\_04\\book.xml");

        Element rool = document.getRootElement();
        List<Element> books = rool.elements();
        List<Book> bb = new ArrayList<>();
        for (Element b : books) {
            Book book = new Book();
            book.setCategory(b.attributeValue("category"));
            book.setTitle(b.element("title").getText());
            book.setAuthor(b.element("author").getText());
            book.setYear(Integer.parseInt(b.element("year").getText()));
            book.setPrice(Double.parseDouble(b.element("price").getText()));
            bb.add(book);
        }
        System.out.println(bb);
    }
}
